<?php
namespace BP\DA;

use BP\En\Entity;

class CashEntity {
	protected static $_Cash;	// Hashtable
	public static function getDCash () 
	{
		if ((self::$_Cash == NULL))
		{
			self::$_Cash = []; //map
		}
		return self::$_Cash;
	}
	public static function PubEns ($enName, $ens, $enPK) // [String enName, Entities ens, String enPK]
	{
		$tempVar = CashEntity::getDCash()->get($enName);
		$ht = ( (is_array($tempVar)) ? $tempVar : NULL );
		if (($ht == NULL))
		{
			$ht = []; //map
		}
		$ht->clear();
		foreach ($ens as $en) 		{
			$ht->put(($en)->GetValStrByKey($enPK), $en);
		}
		CashEntity::getDCash()->put(($enName . "Ens"), $ens);
	}
	public static function GetEns ($enName) // [String enName]
	{
		$tempVar = CashEntity::getDCash()->get(($enName . "Ens"));
		$ens = ( ($tempVar instanceof Entities) ? $tempVar : NULL );
		return $ens;
	}
	public static function Update ($enName, $key, $en) // [String enName, String key, Entity en]
	{
		$tempVar = CashEntity::getDCash()->get($enName);
		$ht = ( (is_array($tempVar)) ? $tempVar : NULL );
		if (($ht == NULL))
		{
			$ht = []; //map
			CashEntity::getDCash()->put($enName, $ht);
		}
		$ht->put($key, $en);
		CashEntity::getDCash()->remove(($enName . "Ens"));
	}
	public static function Select ($enName, $pkVal) // [String enName, String pkVal]
	{
		$tempVar = CashEntity::getDCash()->get($enName);
		$ht = ( (is_array($tempVar)) ? $tempVar : NULL );
		if (($ht == NULL))
		{
			return NULL;
		}
		return ( ($ht->get($pkVal) instanceof Entity) ? $ht->get($pkVal) : NULL );
	}
	public static function Delete ($enName, $pkVal) // [String enName, String pkVal]
	{
		$tempVar = CashEntity::getDCash()->get($enName);
		$ht = ( (is_array($tempVar)) ? $tempVar : NULL );
		if (($ht == NULL))
		{
			return ;
		}
		$ht->remove($pkVal);
		CashEntity::getDCash()->remove(($enName . "Ens"));
	}
	public static function Insert ($enName, $pkVal, $en) // [String enName, String pkVal, Entity en]
	{
		$tempVar = CashEntity::getDCash()->get($enName);
		$ht = ( (is_array($tempVar)) ? $tempVar : NULL );
		if (($ht == NULL))
		{
			return ;
		}
		if ($ht->containsKey($pkVal))
		{
			$ht->put($pkVal, $en);
		}
		else
		{
			$ht->put($pkVal, $en);
		}
		CashEntity::getDCash()->remove(($enName . "Ens"));
	}
}
?>
